using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using DevExpress.XtraReports.UI;
using System.Collections.Generic;
using System.Linq;

namespace QLTV.Reports
{
    public partial class rptVactionList : DevExpress.XtraReports.UI.XtraReport
    {
        public rptVactionList()
        {
            InitializeComponent();
        }
        public void loadData(string department)
        {

            Database.dsReportTableAdapters.tadVacation tadVacation = new Database.dsReportTableAdapters.tadVacation();
            Database.dsReport.tblVacationDataTable dt = new Database.dsReport.tblVacationDataTable();
            tadVacation.Fill(dt);
            List<int> listID = (from d in dt.AsEnumerable()
                                orderby d.nRankLevel, d.dLeave ascending
                                where d.Department.Contains(department)
                                select d.nRankID).Distinct().ToList<int>();

            bool flag = false;
            Datasource data = null;
            List<Datasource> listData = new List<Datasource>();
            for (int i = 0; i < listID.Count; i++)
            {

                data = new Datasource();
                if (i < listID.Count)
                {
                    data.value1 = listID.ToArray()[i];
                }
                else
                    flag = false;
                if (i + 1 < listID.Count)
                {
                    data.value2 = listID.ToArray()[i + 1];
                }
                else
                    flag = false;
                if (i + 2 < listID.Count)
                {
                    data.value3 = listID.ToArray()[i + 2];
                }
                else
                    flag = false;
                if (i + 3 < listID.Count)
                {
                    data.value4 = listID.ToArray()[i + 3];
                    flag = true;
                }
                else
                    flag = false;


                if (data != null)
                    listData.Add(data);
                if (flag)
                {
                    i = i + 3;

                }
                else
                    break;
            }


            this.DataSource = listData;
        }

        private void Detail_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            try
            {
                if (this.GetCurrentColumnValue("value1") != null)
                    if ((Int32)this.GetCurrentColumnValue("value1") != 0)
                    {
                        if (part1.ReportSource == null)
                            part1.ReportSource = rptVacation1;
                        ((rptVacation)part1.ReportSource).loadData((Int32)this.GetCurrentColumnValue("value1"));
                    }
                    else
                        part1.ReportSource = null;
                if (this.GetCurrentColumnValue("value2") != null)
                    if ((Int32)this.GetCurrentColumnValue("value2") != 0)
                    {
                        if (part2.ReportSource == null)
                            part2.ReportSource = rptVacation2;
                        ((rptVacation)part2.ReportSource).loadData((Int32)this.GetCurrentColumnValue("value2"));
                    }
                    else
                        part2.ReportSource = null;
                if (this.GetCurrentColumnValue("value3") != null)
                    if ((Int32)this.GetCurrentColumnValue("value3") != 0)
                    {
                        if (part3.ReportSource == null)
                            part3.ReportSource = rptVacation3;
                        ((rptVacation)part3.ReportSource).loadData((Int32)this.GetCurrentColumnValue("value3"));
                    }
                    else
                        part3.ReportSource = null;
                if (this.GetCurrentColumnValue("value4") != null)
                    if ((Int32)this.GetCurrentColumnValue("value4") != 0)
                    {
                        if (part4.ReportSource == null)
                            part4.ReportSource = rptVacation4;
                        ((rptVacation)part4.ReportSource).loadData((Int32)this.GetCurrentColumnValue("value4"));
                    }
                    else
                        part4.ReportSource = null;
            }
            catch
            { }

        }

    }
}
